<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="搬砖 嵌入式">
<meta property="og:type" content="website">
<meta property="og:title" content="学无止境">
<meta property="og:url" content="http://example.com/page/16/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="搬砖 嵌入式">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="xudonglei">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/page/16/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/05/11/%E5%AF%B9%E7%BB%93%E6%9E%84%E4%BD%93%E6%95%B0%E7%BB%84%E6%8C%89%E6%9F%90%E4%B8%AA%E6%88%90%E5%91%98%E5%A4%A7%E5%B0%8F%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/05/11/%E5%AF%B9%E7%BB%93%E6%9E%84%E4%BD%93%E6%95%B0%E7%BB%84%E6%8C%89%E6%9F%90%E4%B8%AA%E6%88%90%E5%91%98%E5%A4%A7%E5%B0%8F%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/" class="post-title-link" itemprop="url">对结构体数组按某个成员大小快速排序</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-05-11 19:55:47" itemprop="dateCreated datePublished" datetime="2022-05-11T19:55:47+08:00">2022-05-11</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/05/11/%E5%AF%B9%E7%BB%93%E6%9E%84%E4%BD%93%E6%95%B0%E7%BB%84%E6%8C%89%E6%9F%90%E4%B8%AA%E6%88%90%E5%91%98%E5%A4%A7%E5%B0%8F%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/" class="post-meta-item leancloud_visitors" data-flag-title="对结构体数组按某个成员大小快速排序" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/05/11/%E5%AF%B9%E7%BB%93%E6%9E%84%E4%BD%93%E6%95%B0%E7%BB%84%E6%8C%89%E6%9F%90%E4%B8%AA%E6%88%90%E5%91%98%E5%A4%A7%E5%B0%8F%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/05/11/%E5%AF%B9%E7%BB%93%E6%9E%84%E4%BD%93%E6%95%B0%E7%BB%84%E6%8C%89%E6%9F%90%E4%B8%AA%E6%88%90%E5%91%98%E5%A4%A7%E5%B0%8F%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​         废话不说，直接上源码。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">target</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">      <span class="keyword">uint16_t</span> x;</span><br><span class="line">	  <span class="keyword">uint16_t</span> y;</span><br><span class="line">	  <span class="keyword">float</span> pwr;</span><br><span class="line">&#125; target_T;</span><br><span class="line"></span><br><span class="line">target_T   target[<span class="number">5</span>] = &#123;<span class="number">0</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">target_quiksort</span><span class="params">(target_T* target,<span class="keyword">uint8_t</span> low,<span class="keyword">uint8_t</span> high)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">uint8_t</span>     i = low;</span><br><span class="line">    <span class="keyword">uint8_t</span>     j = high;  </span><br><span class="line">    target_T temp = target[i]; </span><br><span class="line">  </span><br><span class="line">    <span class="keyword">if</span>( low &lt; high)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">while</span>(i &lt; j)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">while</span>((target[j].pwr &gt;= temp.pwr) &amp;&amp; (i &lt; j))</span><br><span class="line">            &#123;</span><br><span class="line">                --j;</span><br><span class="line">            &#125;</span><br><span class="line">            target[i] = target[j];</span><br><span class="line">            <span class="keyword">while</span>((target[i].pwr &lt;= temp.pwr) &amp;&amp; (i &lt; j))</span><br><span class="line">            &#123;</span><br><span class="line">                ++i; </span><br><span class="line">            &#125;</span><br><span class="line">            target[j]= target[i];</span><br><span class="line">        &#125;</span><br><span class="line">        target[i] = temp;</span><br><span class="line">        <span class="keyword">if</span>((i<span class="number">-1</span>)&gt;low)</span><br><span class="line">        &#123;</span><br><span class="line">            target_quiksort(target,low,i<span class="number">-1</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(high&gt;j+<span class="number">1</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            target_quiksort(target,j+<span class="number">1</span>,high);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//按target数组中，结构体pwr成员的大小进行排序（由小到大排列）</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    target[<span class="number">0</span>].x = <span class="number">16</span>;</span><br><span class="line">    target[<span class="number">0</span>].y = <span class="number">12</span>;</span><br><span class="line">    target[<span class="number">0</span>].pwr = <span class="number">800.23</span>;</span><br><span class="line"></span><br><span class="line">    target[<span class="number">1</span>].x = <span class="number">26</span>;</span><br><span class="line">    target[<span class="number">1</span>].y = <span class="number">22</span>;</span><br><span class="line">    target[<span class="number">1</span>].pwr = <span class="number">200.23</span>;</span><br><span class="line"></span><br><span class="line">    target[<span class="number">2</span>].x = <span class="number">36</span>;</span><br><span class="line">    target[<span class="number">2</span>].y = <span class="number">32</span>;</span><br><span class="line">    target[<span class="number">2</span>].pwr = <span class="number">400.23</span>;</span><br><span class="line"></span><br><span class="line">    target[<span class="number">3</span>].x = <span class="number">46</span>;</span><br><span class="line">    target[<span class="number">3</span>].y = <span class="number">42</span>;</span><br><span class="line">    target[<span class="number">3</span>].pwr = <span class="number">100.23</span>;</span><br><span class="line"></span><br><span class="line">    target[<span class="number">4</span>].x = <span class="number">56</span>;</span><br><span class="line">    target[<span class="number">4</span>].y = <span class="number">52</span>;</span><br><span class="line">    target[<span class="number">4</span>].pwr = <span class="number">500.23</span>;</span><br><span class="line"></span><br><span class="line">     target_quiksort(target, <span class="number">0</span>, <span class="number">4</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>; i&lt;<span class="number">5</span>; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%d  %d  %f\r\n&quot;</span>,target[i].x, target[i].y, target[i].pwr);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220511195921.png" style="zoom:80%;">

<p>​        对一个数组进行快速排序，代码其实也是类似的：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">quiksort</span><span class="params">(<span class="keyword">float32_t</span> a[],<span class="keyword">uint8_t</span> low,<span class="keyword">uint8_t</span> high)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">uint8_t</span>     i = low;</span><br><span class="line">    <span class="keyword">uint8_t</span>     j = high;  </span><br><span class="line">    <span class="keyword">float32_t</span> temp = a[i]; </span><br><span class="line">  </span><br><span class="line">    <span class="keyword">if</span>( low &lt; high)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">while</span>(i &lt; j)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">while</span>((a[j] &gt;= temp) &amp;&amp; (i &lt; j))</span><br><span class="line">            &#123;</span><br><span class="line">                --j;</span><br><span class="line">            &#125;</span><br><span class="line">            a[i] = a[j];</span><br><span class="line">            <span class="keyword">while</span>((a[i] &lt;= temp) &amp;&amp; (i &lt; j))</span><br><span class="line">            &#123;</span><br><span class="line">                ++i; </span><br><span class="line">            &#125;</span><br><span class="line">            a[j]= a[i];</span><br><span class="line">        &#125;</span><br><span class="line">        a[i] = temp;</span><br><span class="line">        <span class="keyword">if</span>((i<span class="number">-1</span>)&gt;low)</span><br><span class="line">        &#123;</span><br><span class="line">            quiksort(a,low,i<span class="number">-1</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(high&gt;j+<span class="number">1</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            quiksort(a,j+<span class="number">1</span>,high);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/05/11/float32%E6%95%B0%E6%8D%AE%E8%BD%AC%E6%88%90uint8%E7%94%A8%E4%BA%8E%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%91%E9%80%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/05/11/float32%E6%95%B0%E6%8D%AE%E8%BD%AC%E6%88%90uint8%E7%94%A8%E4%BA%8E%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%91%E9%80%81/" class="post-title-link" itemprop="url">float32数据转成uint8用于数据的发送</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-05-11 19:21:19" itemprop="dateCreated datePublished" datetime="2022-05-11T19:21:19+08:00">2022-05-11</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/05/11/float32%E6%95%B0%E6%8D%AE%E8%BD%AC%E6%88%90uint8%E7%94%A8%E4%BA%8E%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%91%E9%80%81/" class="post-meta-item leancloud_visitors" data-flag-title="float32数据转成uint8用于数据的发送" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/05/11/float32%E6%95%B0%E6%8D%AE%E8%BD%AC%E6%88%90uint8%E7%94%A8%E4%BA%8E%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%91%E9%80%81/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/05/11/float32%E6%95%B0%E6%8D%AE%E8%BD%AC%E6%88%90uint8%E7%94%A8%E4%BA%8E%E6%95%B0%E6%8D%AE%E7%9A%84%E5%8F%91%E9%80%81/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​         在调试嵌入式算法的时候，遇到一个情况，需要把float32_t类型数组的数据发送到上位机，上位机接收这些数据进行分析。</p>
<p>​        将float32_t这样类型的数组数据，可以像下面这样的方式进行直接发送：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/发送的数据.png" style="zoom:80%;">

<p>​        我们将发送出去的数据保存下来，看到底发送了哪些数据，如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/通过rtt发送出去的数据.png" style="zoom:80%;">        

<p>​        下面先用C语言将102，230，246，66转换成对应的float32_t类型的值</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220511193424.png" style="zoom:80%;">

<p>​        下面再用python将102，230，246，66，202，110，50，71转换成对应的float32_t类型的值</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220511194142.png" style="zoom:70%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/05/02/simulink%E4%BD%BF%E7%94%A8workspace%E7%9A%84%E6%95%B0%E6%8D%AE%E5%81%9A%E4%BD%8E%E9%80%9A%E6%BB%A4%E6%B3%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/05/02/simulink%E4%BD%BF%E7%94%A8workspace%E7%9A%84%E6%95%B0%E6%8D%AE%E5%81%9A%E4%BD%8E%E9%80%9A%E6%BB%A4%E6%B3%A2/" class="post-title-link" itemprop="url">simulink使用workspace的数据做低通滤波</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-05-02 22:05:27" itemprop="dateCreated datePublished" datetime="2022-05-02T22:05:27+08:00">2022-05-02</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/matlab/" itemprop="url" rel="index"><span itemprop="name">matlab</span></a>
                </span>
            </span>

          
            <span id="/2022/05/02/simulink%E4%BD%BF%E7%94%A8workspace%E7%9A%84%E6%95%B0%E6%8D%AE%E5%81%9A%E4%BD%8E%E9%80%9A%E6%BB%A4%E6%B3%A2/" class="post-meta-item leancloud_visitors" data-flag-title="simulink使用workspace的数据做低通滤波" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/05/02/simulink%E4%BD%BF%E7%94%A8workspace%E7%9A%84%E6%95%B0%E6%8D%AE%E5%81%9A%E4%BD%8E%E9%80%9A%E6%BB%A4%E6%B3%A2/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/05/02/simulink%E4%BD%BF%E7%94%A8workspace%E7%9A%84%E6%95%B0%E6%8D%AE%E5%81%9A%E4%BD%8E%E9%80%9A%E6%BB%A4%E6%B3%A2/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        这个实验中，我们使用workspace的数据，放到simulink中，做低通测试。</p>
<p>​        先造个输入数据：</p>
<figure class="highlight matlab"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">t = (<span class="number">0</span>: <span class="number">0.001</span>: <span class="number">1</span>)&#x27;;</span><br><span class="line">x = <span class="built_in">sin</span>(<span class="number">2</span>*<span class="built_in">pi</span>*<span class="number">1</span>*t) + <span class="number">0.1</span>*<span class="built_in">sin</span>(<span class="number">2</span>*<span class="built_in">pi</span>*<span class="number">50</span>*t);</span><br><span class="line"><span class="built_in">plot</span>(t, x)</span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022210944.jpg" style="zoom:50%;">

<p>​        simulink从工作空间导入数据流程：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022213676.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022214261.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022215394.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022217516.png" style="zoom:70%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022219504.png" style="zoom:50%;">

<p>现在通过scope可以直接看到波形，将运行时间改成1，然后点击运行：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022221028.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022221075.png" style="zoom:50%;">

<p>​        现在添加一个低通模块：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022224845.png" style="zoom:80%;">

<p>​        将scope的输入改成2：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022226015.png" style="zoom:50%;">

<p>​        修改滤波器的参数：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022233421.png" style="zoom:70%;">

<p>​        显示最后的结果：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202205022234392.png" style="zoom:67%;">


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/04/28/iir%E7%9B%B4%E6%8E%A5i%E5%9E%8B%E5%92%8C%E7%9B%B4%E6%8E%A5ii%E5%9E%8B%E6%BB%A4%E6%B3%A2%E5%99%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/04/28/iir%E7%9B%B4%E6%8E%A5i%E5%9E%8B%E5%92%8C%E7%9B%B4%E6%8E%A5ii%E5%9E%8B%E6%BB%A4%E6%B3%A2%E5%99%A8/" class="post-title-link" itemprop="url">iir直接i型和直接ii型滤波器</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-04-28 22:26:35" itemprop="dateCreated datePublished" datetime="2022-04-28T22:26:35+08:00">2022-04-28</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
                </span>
            </span>

          
            <span id="/2022/04/28/iir%E7%9B%B4%E6%8E%A5i%E5%9E%8B%E5%92%8C%E7%9B%B4%E6%8E%A5ii%E5%9E%8B%E6%BB%A4%E6%B3%A2%E5%99%A8/" class="post-meta-item leancloud_visitors" data-flag-title="iir直接i型和直接ii型滤波器" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/04/28/iir%E7%9B%B4%E6%8E%A5i%E5%9E%8B%E5%92%8C%E7%9B%B4%E6%8E%A5ii%E5%9E%8B%E6%BB%A4%E6%B3%A2%E5%99%A8/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/04/28/iir%E7%9B%B4%E6%8E%A5i%E5%9E%8B%E5%92%8C%E7%9B%B4%E6%8E%A5ii%E5%9E%8B%E6%BB%A4%E6%B3%A2%E5%99%A8/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文链接：<a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_30463341/article/details/98240773">https://blog.csdn.net/weixin_30463341/article/details/98240773</a></p>
<h3 id="1-IIR滤波器构造"><a href="#1-IIR滤波器构造" class="headerlink" title="1.IIR滤波器构造"></a>1.IIR滤波器构造</h3><p>​        IIR滤波器的单位冲击响应是无限的！用差分方程来表达一个滤波器，应该是下式这个样子的。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204282229759.png"></p>
<p>这个式子是N次差分方程的表达式。我们明显可以看出，计算输出y(n)的时候，需要以前的输出值与输入值。换言之，这个可能表达式还有反馈环节。当 <img src="https://img-blog.csdn.net/20130605220801390" alt="img">为0的时候，这个滤波器由于没有反馈，其单位冲击响应是有限的，是FIR滤波器。当 <img src="https://img-blog.csdn.net/20130605220801390" alt="img">不为0是时候，是IIR滤波器。</p>
<h3 id="2-直接I型IIR滤波器"><a href="#2-直接I型IIR滤波器" class="headerlink" title="2.直接I型IIR滤波器"></a>2.直接I型IIR滤波器</h3><p>​        就如同之前所说一样，我们考虑这样一个滤波器。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204282230980.png"></p>
<p>很明显，这是一个1阶才差分方程。由于 <img src="https://img-blog.csdn.net/20130605220801390" alt="img">不为0，这是一个1阶IIR滤波器的差分方程。为了方便观察，我们将其画系统成框图。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204282231452.png"></p>
<p>​        很明显的，要实现这个滤波器，我们需要2个单位的存储空间，用来存储过去的输入值与输出值。这样的话，考虑N阶的滤波器，我们就需要2N个存储单元。这种结构被称作直接I型结构。</p>
<h3 id="3-直接II型IIR滤波器"><a href="#3-直接II型IIR滤波器" class="headerlink" title="3.直接II型IIR滤波器"></a>3.直接II型IIR滤波器</h3><p>​        我们先观察上图的直接I型滤波器，将其视为有两个较小系统串联而成的系统。由于是串联，那么，顺序必定不影响输入输出结果，那么，我们将其调整一下位置。得到就像下图一样的一个新的系统。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204282232827.png"></p>
<p>​        然后，我们可以发现，其实，这个系统完全没有必要使用两个延迟算子，可以合并使用。将其延迟算子合并，那么，可以得到下面这样一个系统。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204282233355.png"></p>
<p>​         这个系统与之前的直接I型系统一样，拥有完全相同的输入输出特性。并且，节省了一半的延迟算子。实现这个滤波器所需要的存储空间为N。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/04/17/SeggerRtt%E4%BC%A0%E8%BE%93%E5%A4%A7%E6%95%B0%E6%8D%AE%E9%87%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/04/17/SeggerRtt%E4%BC%A0%E8%BE%93%E5%A4%A7%E6%95%B0%E6%8D%AE%E9%87%8F/" class="post-title-link" itemprop="url">SeggerRtt传输大数据量</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-04-17 15:22:50" itemprop="dateCreated datePublished" datetime="2022-04-17T15:22:50+08:00">2022-04-17</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/04/17/SeggerRtt%E4%BC%A0%E8%BE%93%E5%A4%A7%E6%95%B0%E6%8D%AE%E9%87%8F/" class="post-meta-item leancloud_visitors" data-flag-title="SeggerRtt传输大数据量" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/04/17/SeggerRtt%E4%BC%A0%E8%BE%93%E5%A4%A7%E6%95%B0%E6%8D%AE%E9%87%8F/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/04/17/SeggerRtt%E4%BC%A0%E8%BE%93%E5%A4%A7%E6%95%B0%E6%8D%AE%E9%87%8F/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        最近在调试算法，需要把mcu上的一个大数组全部传出来，然后在电脑上用python进行分析，但是数据量比较大，同时传输间隔又短，串口来不及传输，后来调研下来发现可以使用segger RTT实现。</p>
<p>​        segger RTT的移植这边就不说了，网上一大把，主要说一下这里的思路。mcu上移植好rtt，就可以发送数据了，然后电脑端发现可以使用python调用JLink_x64.dll来实现数据的接收，完美开整。</p>
<h3 id="一、MCU端"><a href="#一、MCU端" class="headerlink" title="一、MCU端"></a>一、MCU端</h3><p>​        这里主要介绍一下mcu端涉及到我们写代码需要注意的地方。</p>
<ul>
<li><strong>SEGGER_RTT_MAX_NUM_UP_BUFFERS</strong>：最大上行缓存数量，默认为3；</li>
<li><strong>SEGGER_RTT_MAX_NUM_DOWN_BUFFERS</strong>：最大下行缓存数量，默认为3；</li>
<li><strong>BUFFER_SIZE_UP</strong>：上行缓存大小，默认为1024字节</li>
<li><strong>BUFFER_SIZE_DOWN</strong>：下行缓存大小，默认为16字节</li>
<li><strong>SEGGER_RTT_PRINTF_BUFFER_SIZE</strong>：RTT printf()缓存大小，默认为64字节</li>
<li><strong>SEGGER_RTT_MODE_DEFAULT</strong>：RTT内存块工作模式</li>
</ul>
<p>​    用户可以根据自己的实际需求，对这些参数进行配置，也可以使用其默认配置工作。</p>
<p>​    其中，RTT内存块工作模式工作模式可以配置为以下三种之一：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> SEGGER_RTT_MODE_NO_BLOCK_SKIP         (0)     <span class="comment">// Skip. Do not block, output nothing. (Default)</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> SEGGER_RTT_MODE_NO_BLOCK_TRIM         (1)     <span class="comment">// Trim: Do not block, output as much as fits.</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL    (2)     <span class="comment">// Block: Wait until there is space in the buffer.</span></span></span><br></pre></td></tr></table></figure>
<p>​        前面两种都是<strong>非阻塞方式</strong>，差别是写入数据长度大于当前buffer中可用空间时，是跳过不写入任何数据(<strong>SKIP</strong>)，还是写入尽量多的数据(<strong>TRIM</strong>, 比如要写入5个字节“Hello”，而当前buffer只剩2个字节空间了，则将“He”写入，而“llo”则被忽略)；</p>
<p>​        若选择<strong>SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL</strong> ，在写入数据长度大于当前buffer中可用空间时，RTT将阻塞CPU内核，等待buffer中的数据为J-LINK上位机取走，再写入。这种方式虽然可以避免数据丢失，但是在脱机运行(不连接J-LINK上位机软件)时，将会阻塞CPU运行，因此，需要特别小心。</p>
<p>​        我的工程里就故意设置成SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL，因为配合我板子上的led灯，我可以方便的看到我发送的数据是不是有丢。</p>
<p>​        还有一个我更改的配置是：#define BUFFER_SIZE_UP     (1024*40)   默认是1024，这里加大之后，数据确实来得及发送了。</p>
<h3 id="二、电脑端"><a href="#二、电脑端" class="headerlink" title="二、电脑端"></a>二、电脑端</h3><p>​        电脑端可以使用python来实现数据接收，这里搬运了网上大神写的代码，稍加修改后实测没有问题。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> ctypes</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">RingBuffer</span>(<span class="params">ctypes.Structure</span>):</span></span><br><span class="line">    _fields_ = [</span><br><span class="line">        (<span class="string">&#x27;sName&#x27;</span>, ctypes.c_uint),  <span class="comment"># ctypes.POINTER(ctypes.c_char)，64位Python中 ctypes.POINTER 是64位的，与目标芯片不符</span></span><br><span class="line">        (<span class="string">&#x27;pBuffer&#x27;</span>, ctypes.c_uint),  <span class="comment"># ctypes.POINTER(ctypes.c_byte)</span></span><br><span class="line">        (<span class="string">&#x27;SizeOfBuffer&#x27;</span>, ctypes.c_uint),</span><br><span class="line">        (<span class="string">&#x27;WrOff&#x27;</span>, ctypes.c_uint),  <span class="comment"># Position of next item to be written. 对于aUp：   芯片更新WrOff，主机更新RdOff</span></span><br><span class="line">        (<span class="string">&#x27;RdOff&#x27;</span>, ctypes.c_uint),  <span class="comment"># Position of next item to be read.    对于aDown： 主机更新WrOff，芯片更新RdOff</span></span><br><span class="line">        (<span class="string">&#x27;Flags&#x27;</span>, ctypes.c_uint),</span><br><span class="line">    ]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SEGGER_RTT_CB</span>(<span class="params">ctypes.Structure</span>):</span>  <span class="comment"># Control Block</span></span><br><span class="line">    _fields_ = [</span><br><span class="line">        (<span class="string">&#x27;acID&#x27;</span>, ctypes.c_char * <span class="number">16</span>),</span><br><span class="line">        (<span class="string">&#x27;MaxNumUpBuffers&#x27;</span>, ctypes.c_uint),</span><br><span class="line">        (<span class="string">&#x27;MaxNumDownBuffers&#x27;</span>, ctypes.c_uint),</span><br><span class="line">        (<span class="string">&#x27;aUp&#x27;</span>, RingBuffer * <span class="number">2</span>),</span><br><span class="line">        (<span class="string">&#x27;aDown&#x27;</span>, RingBuffer * <span class="number">2</span>),</span><br><span class="line">    ]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">RTT</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">connectdevice</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="comment"># 初始化连接上目标</span></span><br><span class="line">        self.jlink = ctypes.cdll.LoadLibrary(<span class="string">&#x27;./JLink_x64.dll&#x27;</span>)</span><br><span class="line">        err_buf = (ctypes.c_char * <span class="number">64</span>)()</span><br><span class="line">        self.jlink.JLINKARM_ExecCommand(<span class="string">f&#x27;Device = Cortex-M4&#x27;</span>.encode(<span class="string">&#x27;latin-1&#x27;</span>), err_buf, <span class="number">64</span>)</span><br><span class="line">        self.jlink.JLINKARM_TIF_Select(<span class="number">1</span>)</span><br><span class="line">        self.jlink.JLINKARM_SetSpeed(<span class="number">4000</span>)</span><br><span class="line"></span><br><span class="line">        buff = ctypes.create_string_buffer(<span class="number">1024</span>)</span><br><span class="line">        Addr = <span class="number">536870912</span>  <span class="comment"># 0x20000000</span></span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">128</span>):</span><br><span class="line">            self.jlink.JLINKARM_ReadMem(Addr + <span class="number">1024</span> * i, <span class="number">1024</span>, buff)</span><br><span class="line">            index = buff.raw.find(<span class="string">b&#x27;SEGGER RTT&#x27;</span>)</span><br><span class="line">            <span class="keyword">if</span> index != -<span class="number">1</span>:</span><br><span class="line">                self.RTTAddr = Addr + <span class="number">1024</span> * i + index</span><br><span class="line">                buff = ctypes.create_string_buffer(ctypes.sizeof(SEGGER_RTT_CB))</span><br><span class="line">                self.jlink.JLINKARM_ReadMem(self.RTTAddr, ctypes.sizeof(SEGGER_RTT_CB), buff)</span><br><span class="line">                rtt_cb = SEGGER_RTT_CB.from_buffer(buff)</span><br><span class="line">                self.aUpAddr = self.RTTAddr + <span class="number">16</span> + <span class="number">4</span> + <span class="number">4</span></span><br><span class="line">                self.aDownAddr = self.aUpAddr + ctypes.sizeof(RingBuffer) * rtt_cb.MaxNumUpBuffers</span><br><span class="line">                print(self.RTTAddr, rtt_cb.MaxNumUpBuffers, rtt_cb.MaxNumDownBuffers)</span><br><span class="line">                <span class="keyword">break</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">aUpRead</span>(<span class="params">self</span>):</span></span><br><span class="line">        buf = ctypes.create_string_buffer(ctypes.sizeof(RingBuffer))</span><br><span class="line">        self.jlink.JLINKARM_ReadMem(self.aUpAddr, ctypes.sizeof(RingBuffer), buf)</span><br><span class="line">        aUp = RingBuffer.from_buffer(buf)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> aUp.RdOff == aUp.WrOff:</span><br><span class="line">            <span class="built_in">str</span> = ctypes.create_string_buffer(<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">elif</span> aUp.RdOff &lt; aUp.WrOff:</span><br><span class="line">            cnt = aUp.WrOff - aUp.RdOff</span><br><span class="line">            <span class="built_in">str</span> = ctypes.create_string_buffer(cnt)</span><br><span class="line">            self.jlink.JLINKARM_ReadMem(ctypes.cast(aUp.pBuffer, ctypes.c_void_p).value + aUp.RdOff, cnt, <span class="built_in">str</span>)</span><br><span class="line">            aUp.RdOff += cnt</span><br><span class="line">            self.jlink.JLINKARM_WriteU32(self.aUpAddr + <span class="number">4</span> * <span class="number">4</span>, aUp.RdOff)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            cnt = aUp.SizeOfBuffer - aUp.RdOff</span><br><span class="line">            <span class="built_in">str</span> = ctypes.create_string_buffer(cnt)</span><br><span class="line">            self.jlink.JLINKARM_ReadMem(ctypes.cast(aUp.pBuffer, ctypes.c_void_p).value + aUp.RdOff, cnt, <span class="built_in">str</span>)</span><br><span class="line">            aUp.RdOff = <span class="number">0</span></span><br><span class="line">            self.jlink.JLINKARM_WriteU32(self.aUpAddr + <span class="number">4</span> * <span class="number">4</span>, aUp.RdOff)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">str</span>.raw</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/04/16/Vivado2018.3%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/04/16/Vivado2018.3%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/" class="post-title-link" itemprop="url">Vivado2018.3安装教程</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-04-16 12:13:21" itemprop="dateCreated datePublished" datetime="2022-04-16T12:13:21+08:00">2022-04-16</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/FPGA/" itemprop="url" rel="index"><span itemprop="name">FPGA</span></a>
                </span>
            </span>

          
            <span id="/2022/04/16/Vivado2018.3%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/" class="post-meta-item leancloud_visitors" data-flag-title="Vivado2018.3安装教程" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/04/16/Vivado2018.3%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/04/16/Vivado2018.3%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        Vivado18.3是18年的最后一个版本，正常来讲每年的最后一个版本即为相对稳定的版本。</p>
<h3 id="Step1："><a href="#Step1：" class="headerlink" title="Step1："></a>Step1：</h3><p>​    解压安装包，安装包大约19G，比较大。解压完成后，进去文件夹，找到xsetup.exe以管理员身份运行它。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171304279.png" style="zoom:60%;">

<h3 id="Step2："><a href="#Step2：" class="headerlink" title="Step2："></a>Step2：</h3><p>​        进入到Vivado18.3的安装界面，窗口提示有更新的版本，我们不用新版本，点击Continue，next。</p>
<p>​    <img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171309873.png" style="zoom:57%;"></p>
<h3 id="Step3："><a href="#Step3：" class="headerlink" title="Step3："></a>Step3：</h3><p>​    在下面这个界面，I Agree 全部点上，然后再点击 NEXT：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171311317.png" style="zoom:57%;">

<h3 id="Step4："><a href="#Step4：" class="headerlink" title="Step4："></a>Step4：</h3><p>​        进入到安装版本选择。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171314906.png" style="zoom:57%;">

<p>​        一共有4个版本可供选择。Documentation Navigator (Standalone)</p>
<p>​        Vivado HL WebPCK:这个是功能最少的版本，也是不需要付费或者破解Lincense的版本。</p>
<p>​        Vivado HL Design Edition:这个已经是功能非常齐全的版本。没有特殊需要，这个版本足够用。</p>
<p>​        Vivado HL System Edition:这个比Design Edition多了一些其他的工具。（比如多了system generator for dsp 工具）。</p>
<p>​        Documentation Navigator (Standalone):这个是单独安装文档的选项，我们安装上面DE或者SE时都会有文档安装，所以不需要它。</p>
<p>​        因为可能会用的一些其他工具，我这里选择安装System Edition。没有特殊需求安装Design Edition足够。选择之后点击Next。</p>
<h3 id="Step5："><a href="#Step5：" class="headerlink" title="Step5："></a>Step5：</h3><p>​        下面这个界面是安装组件选择界面。为了方便起见，我这边默认不变，然后点击 NEXT：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171321435.png" style="zoom:57%;">

<h3 id="Step6："><a href="#Step6：" class="headerlink" title="Step6："></a>Step6：</h3><p>​        选择安装路径和快捷方式，这里要注意安装路径中不能有中文。右边这些就是一些快捷方式的选择，我们都选上。点击Next，进入下一步。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171325254.png" style="zoom:57%;">

<p>然后就是漫长的安装过程了。我们安装后打开软件，发现有报错，如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171345694.png" style="zoom:67%;">

<p>这是因为缺少了动态链接库也就是以DLL结尾的文件，我们下载一份加进去即可，<a target="_blank" rel="noopener" href="https://cn.dll-files.com/vcruntime140_1.dll.html%E3%80%82%E8%A7%A3%E5%8E%8B%E5%90%8E%E5%B0%86vcruntime140_1.dll%E5%A4%8D%E5%88%B6%E5%88%B0C:/Windows/System32%E5%8D%B3%E5%8F%AF%E3%80%82">https://cn.dll-files.com/vcruntime140_1.dll.html。解压后将vcruntime140_1.dll复制到C:\Windows\System32即可。</a></p>
<h3 id="Step7："><a href="#Step7：" class="headerlink" title="Step7："></a>Step7：</h3><p>​        license的配置。我们点击左边菜单栏的 Load License 然后点击右边 Copy License…，找到提供的</p>
<p>license 文件，打开。然后就加载进来了。建议把安装包中的多个license都添加一遍，然后我们点击左边的菜单栏的 Viw License Status，可以看到 License 状态信息。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171354288.png" style="zoom:57%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171355477.png" style="zoom:57%;">

<p>到此，VIVADO 开发环境全部安装完成。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/04/16/Vivado%E6%96%B0%E5%BB%BAZYNQ%E5%B7%A5%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/04/16/Vivado%E6%96%B0%E5%BB%BAZYNQ%E5%B7%A5%E7%A8%8B/" class="post-title-link" itemprop="url">Vivado新建ZYNQ工程</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-04-16 12:13:21" itemprop="dateCreated datePublished" datetime="2022-04-16T12:13:21+08:00">2022-04-16</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/FPGA/" itemprop="url" rel="index"><span itemprop="name">FPGA</span></a>
                </span>
            </span>

          
            <span id="/2022/04/16/Vivado%E6%96%B0%E5%BB%BAZYNQ%E5%B7%A5%E7%A8%8B/" class="post-meta-item leancloud_visitors" data-flag-title="Vivado新建ZYNQ工程" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/04/16/Vivado%E6%96%B0%E5%BB%BAZYNQ%E5%B7%A5%E7%A8%8B/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/04/16/Vivado%E6%96%B0%E5%BB%BAZYNQ%E5%B7%A5%E7%A8%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h3 id="Step1"><a href="#Step1" class="headerlink" title="Step1:"></a>Step1:</h3><p>​        ZYNQ工程建立可通过菜单栏file-&gt;Project-&gt;New启动新建工程向导，也可以通过Quick Start的Create Project启动,然后点击NEXT。工程的名和工程建立的目录，这里我们工程名为 zynq_test，我们在 d 盘下面新建</p>
<p>一个文件夹，命名为WorkSpace,然后工程位置选择这个文件夹路径然后点击NEXT:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171500262.png" style="zoom:67%;">

<h3 id="Step2"><a href="#Step2" class="headerlink" title="Step2:"></a>Step2:</h3><p>​        工程类型选择，这里我们默认选择 RTL 工程，然后点击 NEXT:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171511399.png" style="zoom:67%;">

<h3 id="Step3"><a href="#Step3" class="headerlink" title="Step3:"></a>Step3:</h3><p>​        添加源文件。可以添加 FPGA 的源代码文件，这里只支持 VHDL 或者 verilog 文件。如果我们已有设计源代码，可以在这里添加。如果没有添加，工程新建好了之后想要重新添加也可以在其他地方添加进来。这里默认不添加，点击 NEXT:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171513524.png" style="zoom:67%;">

<h3 id="Step4"><a href="#Step4" class="headerlink" title="Step4:"></a>Step4:</h3><p>​        添加约束文件。如果我们已有约束文件（约束文件可能包含时许约束，可能包含管脚约束等信息），可以在这里添加进来，也可以工程建立完成之后再添加。这里我们不添加，点击 NEXT：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171514868.png" style="zoom:67%;">

<h3 id="Step5"><a href="#Step5" class="headerlink" title="Step5:"></a>Step5:</h3><p>​        选择芯片型号。这里 Category 默认，Family 选择 Zynq-7000，Packege 封装选择 clg-400，Speed 选择-1,在最后出现的列表选择 xc7z010clg400-1。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204171532442.png" style="zoom:67%;">

<h3 id="Step6"><a href="#Step6" class="headerlink" title="Step6:"></a>Step6:</h3><p>​        确认新建的工程信息是否正确。然后点击 Finish，这样工程就建立完毕。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/04/15/Anaconda%E5%A4%8D%E5%88%B6%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/04/15/Anaconda%E5%A4%8D%E5%88%B6%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83/" class="post-title-link" itemprop="url">Anaconda复制虚拟环境</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-04-15 21:20:10" itemprop="dateCreated datePublished" datetime="2022-04-15T21:20:10+08:00">2022-04-15</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2022/04/15/Anaconda%E5%A4%8D%E5%88%B6%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83/" class="post-meta-item leancloud_visitors" data-flag-title="Anaconda复制虚拟环境" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/04/15/Anaconda%E5%A4%8D%E5%88%B6%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/04/15/Anaconda%E5%A4%8D%E5%88%B6%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        在本机上使用下面的指令来复制虚拟环境，记好在base环境下进行。</p>
<p>conda create -n  new_env  –clone  old_env</p>
<p>其中nex_env为新环境名字，old_env为旧环境名字。</p>
<p>​        然后使能新复制好的环境，如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/conda active.png" style="zoom:67%;">

<p>​        最后在anaconda中使用这个新的环境，如下图所示：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20220415213228.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/04/06/%E6%95%B0%E5%AD%97%E6%B3%A2%E6%9D%9F%E5%BD%A2%E6%88%90/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/04/06/%E6%95%B0%E5%AD%97%E6%B3%A2%E6%9D%9F%E5%BD%A2%E6%88%90/" class="post-title-link" itemprop="url">数字波束形成</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-04-06 19:59:34" itemprop="dateCreated datePublished" datetime="2022-04-06T19:59:34+08:00">2022-04-06</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%9B%B7%E8%BE%BE/" itemprop="url" rel="index"><span itemprop="name">雷达</span></a>
                </span>
            </span>

          
            <span id="/2022/04/06/%E6%95%B0%E5%AD%97%E6%B3%A2%E6%9D%9F%E5%BD%A2%E6%88%90/" class="post-meta-item leancloud_visitors" data-flag-title="数字波束形成" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/04/06/%E6%95%B0%E5%AD%97%E6%B3%A2%E6%9D%9F%E5%BD%A2%E6%88%90/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/04/06/%E6%95%B0%E5%AD%97%E6%B3%A2%E6%9D%9F%E5%BD%A2%E6%88%90/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        本文很多内容直接来自于网络，感谢网络上的各位大佬，用的原文链接如下：<a target="_blank" rel="noopener" href="https://blog.csdn.net/Shen_KL/article/details/121433214">https://blog.csdn.net/Shen_KL/article/details/121433214</a></p>
<p>​        相控阵天线是由多个天线单元按某种规律排列而成的天线单元网络，而数字波束形成是相控阵领域特有的技术。</p>
<p>​        对于无方向性的单个天线单元而言，其方向图是全向的。但是，我们可以利用数字信号处理的方式，对每一个天线阵元通道做相位补偿（此处补偿的相位差是由天线阵元空间位置的差异导致每个阵元接收信号的波程差引起的），使得天线阵元对期望方向的信号做同相叠加，最大化该方向的接受增益，实现该方向的是波束形成。而相位补偿最常用的方式就是加权。如下图所示，<br><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204042217494.png" style="zoom:40%;"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204042219167.png"></p>
<figure class="highlight matlab"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">%天线方向图</span></span><br><span class="line">clear all;clc;close all;</span><br><span class="line">N=<span class="number">11</span>;                    <span class="comment">% 阵元数目</span></span><br><span class="line">d_lambda=<span class="number">0.5</span>;            <span class="comment">% 阵元间距半波长</span></span><br><span class="line">theta0=<span class="number">15</span>;               <span class="comment">% 波束指向</span></span><br><span class="line">theta=<span class="number">-90</span>:<span class="number">0.1</span>:<span class="number">90</span>;        <span class="comment">% -90，-89.9，-89.8，-89.7。。。</span></span><br><span class="line">win=taylorwin(N);</span><br><span class="line">theta0=theta0*<span class="built_in">pi</span>/<span class="number">180</span>;</span><br><span class="line">theta=theta*<span class="built_in">pi</span>/<span class="number">180</span>;</span><br><span class="line">a0=<span class="built_in">exp</span>(<span class="number">1</span><span class="built_in">i</span>*<span class="number">2</span>*<span class="built_in">pi</span>*d_lambda*(<span class="number">0</span>:N<span class="number">-1</span>)&#x27;*<span class="built_in">sin</span>(theta0)); <span class="comment">% 导向矢量11*1,感兴趣的那个角度</span></span><br><span class="line">a=<span class="built_in">exp</span>(<span class="number">1</span><span class="built_in">i</span>*<span class="number">2</span>*<span class="built_in">pi</span>*d_lambda*(<span class="number">0</span>:N<span class="number">-1</span>)&#x27;*<span class="built_in">sin</span>(theta));   <span class="comment">% 11*1801</span></span><br><span class="line">ww=a0.*win;                                    <span class="comment">% 对权矢量加窗</span></span><br><span class="line">pattern1=<span class="built_in">abs</span>(ww&#x27;*a);                           <span class="comment">% 1*1801</span></span><br><span class="line">pattern2=<span class="built_in">abs</span>(a0&#x27;*a);                           <span class="comment">% 1*1801</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">figure</span>;</span><br><span class="line"><span class="built_in">plot</span>(theta*<span class="number">180</span>/<span class="built_in">pi</span>,<span class="number">20</span>*<span class="built_in">log10</span>(pattern1/<span class="built_in">max</span>(pattern1)),<span class="string">&#x27;-&#x27;</span>,theta*<span class="number">180</span>/<span class="built_in">pi</span>,<span class="number">20</span>*<span class="built_in">log10</span>(pattern2/<span class="built_in">max</span>(pattern2)),<span class="string">&#x27;--&#x27;</span>);</span><br><span class="line">xlabel(<span class="string">&#x27;方位角/(°)&#x27;</span>);ylabel(<span class="string">&#x27;归一化方向图/dB&#x27;</span>);</span><br><span class="line"><span class="built_in">legend</span>(<span class="string">&#x27;加权&#x27;</span>,<span class="string">&#x27;未加权&#x27;</span>);</span><br><span class="line">grid on;</span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204042223883.jpg" style="zoom:23%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204042221545.png" style="zoom:67%;">

<p>现在改变W,比如我对60°方向的波束感兴趣，将theta0的值改成60，看结果如下图：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204042228973.png" style="zoom:67%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/04/05/%E5%85%89%E8%80%A6H11L1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/04/05/%E5%85%89%E8%80%A6H11L1/" class="post-title-link" itemprop="url">光耦H11L1</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-04-05 20:19:06" itemprop="dateCreated datePublished" datetime="2022-04-05T20:19:06+08:00">2022-04-05</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%A1%AC%E4%BB%B6/" itemprop="url" rel="index"><span itemprop="name">硬件</span></a>
                </span>
            </span>

          
            <span id="/2022/04/05/%E5%85%89%E8%80%A6H11L1/" class="post-meta-item leancloud_visitors" data-flag-title="光耦H11L1" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/04/05/%E5%85%89%E8%80%A6H11L1/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/04/05/%E5%85%89%E8%80%A6H11L1/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        最近使用光耦H11L1，驱动发现一直失败，电路如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204052022587.png" style="zoom:80%;">

<p>​        其中ADSCL引脚直接连到了单片机的IO口。</p>
<p>​        首先看一下输入ADSCL和SCLK电平的关系：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202204052025834.png" style="zoom:80%;">

<p>因此如果ADSCL为低电平，SCLK也为低电平。</p>
<p>​        对了，开头说了驱动不成功，ADSCL不论输入高或者低，SCLK的电平一直没变。怀疑是驱动电流不足，将之前引脚配置的推挽输出模式修改掉，换成开漏输出就可以了，设置开漏输出的那个引脚已经加了上拉电阻。</p>
<p>​        推挽输出——可以输出高，低电平，连接数字器件。</p>
<p>​        开漏输出——输出端相当于三极管的集电极， 要得到高电平状态需要上拉电阻才行，适合于做电流型的驱动，<strong>其吸收电流的能力相对强</strong>(一般20ma以内)。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/15/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/15/">15</a><span class="page-number current">16</span><a class="page-number" href="/page/17/">17</a><span class="space">&hellip;</span><a class="page-number" href="/page/29/">29</a><a class="extend next" rel="next" href="/page/17/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
